Repository navigation
Fix failed and stalled reads on secure connections - #39
Merged
Merged
Conversation
GrahamCampbell
force-pushed
the
fix-secure-reads
branch
from
November 25, 2026 22:54
f6b8d36 to
14349f6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since 1.8.1 the client has failed to connect or stalled for the socket timeout on
wss://connections, as reported in #36. There are two causes. A readable socket does not always hold application data on an encrypted stream, because TLS 1.3 session tickets and partly received records make it readable too, so waiting once and then reading once could return nothing and fail the handshake. And polling withstream_select()before a blockingfread()lets PHP move decrypted bytes into its own buffer, after which PHP before 8.4.24 and 8.5.9 blocks for the whole socket timeout while topping that buffer up. On PHP before 8.2.19 and 8.3.7 thefeof()call can also wait indefinitely on an incomplete record.receive()now reads in non-blocking mode and restores blocking mode afterwards, so it cannot wait on any PHP version, and when given a wait time it keeps waiting until application data arrives or the time runs out. As before, it reads once from the socket and carries on only while PHP still holds buffered bytes, so a read from an unbuffered stream, which is what the server accepts, stays bounded by the length asked for, and a single call is now also capped at 64 KiB.connect()reads until the end of the response headers instead of reading once, which also fixes handshakes whose response arrives in more than one read, and it passes anything that follows the headers to the payload handler so that a frame sent together with the response is no longer lost. Payloads still queued from an earlier connection are discarded when connecting again. On the server, an empty read from a socket that is still connected is no longer treated as the client closing the connection.The new tests use a TLS connection set up inside the test process, whose encrypted bytes reach the client only when the test delivers them, so an incomplete record can be reproduced without a second process.